//
//  ApplyResultViewController.m
//  YongChuanTradingArea
//
//  Created by Vivian on 2017/9/28.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "ApplyResultViewController.h"
#import "ApplyMemberShopViewController.h"
#import "ApplyIndividualViewController.h"
#import "ApplyViewController.h"

@interface ApplyResultViewController ()
@property (weak, nonatomic) IBOutlet UILabel *accLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *areaLabel;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UILabel *waitLabel;
@property (weak, nonatomic) IBOutlet UIButton *applyBtn;
@property (nonatomic, strong) UserModel *model;
@end

@implementation ApplyResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"申请结果";
    [self drawDashLine:self.lineView lineLength:4 lineSpacing:4 lineColor:[UIColor colorWithHexString:@"#dcdcdc"]];
    [self requestData];
    // Do any additional setup after loading the view from its nib.
    if ([_model.MEMBERSTATUS integerValue] == 2 || [_model.MEMBERSTATUS integerValue] == 4)
    {
        [_applyBtn setTitle:@"修改信息" forState:UIControlStateNormal];
    }
}

- (void)setModel:(UserModel *)model{
    _model = model;
    self.waitLabel.hidden = NO;
    self.accLabel.text = _model.USERNAME;
    self.companyNameLabel.text = _model.MEMBERNAME;
    self.areaLabel.text = _model.ADDRESS;
    self.applyBtn.hidden = YES;
    switch ([_model.MEMBERSTATUS integerValue]) {
        case 0:
            self.statusLabel.text = @"待初审";
            break;
        case 1:
            self.statusLabel.text = @"待终审";
            break;
        case 2:
            self.statusLabel.text = @"初审未通过";
            self.applyBtn.hidden = NO;
            self.waitLabel.hidden = YES;
            break;
        case 3:
            self.statusLabel.text = @"终审通过";
            self.waitLabel.hidden = YES;
            break;
        case 4:
            self.statusLabel.text = @"审核未通过";
            self.applyBtn.hidden = NO;
            self.waitLabel.hidden = YES;
            break;
        case -1:
            self.statusLabel.text = @"新增";
            break;
        default:
            self.statusLabel.text = @"审核中";
            break;
    }
    switch ([_model.USERTYPE integerValue]) {
        case 1:
        {
            self.typeLabel.text = @"消费股东";
        }
            break;
        case 2:
        {
            self.typeLabel.text = @"会员店";
        }
            break;
        case 3:
        {
            self.typeLabel.text = @"企业合伙人";
        }
            break;
        case 4:
        {
            self.typeLabel.text = @"个人合伙人";
        }
            break;
            
        default:
            break;
    }
}

- (IBAction)applyBtnAction:(UIButton *)sender {
    if ([_model.USERTYPE isEqualToString:@"2"]) {
        // 注册会员店
        ApplyMemberShopViewController * vc = [[ApplyMemberShopViewController alloc]init];
        vc.isMember = YES;
        vc.isAgain = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([_model.USERTYPE isEqualToString:@"3"]){
        //企业合伙人
        ApplyMemberShopViewController * vc = [[ApplyMemberShopViewController alloc]init];
        vc.isMember = NO;
        vc.isAgain = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([_model.USERTYPE isEqualToString:@"4"]){
        //注册个人合伙人
        ApplyIndividualViewController * vc = [[ApplyIndividualViewController alloc]init];
        vc.isAgain = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
    else{
        ApplyViewController * vc = [[ApplyViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (IBAction)contactBtnAction:(UIButton *)sender {
    
}

#pragma mark - request data
- (void)requestData{
    __weak typeof(self) weakSelf = self;
    [LBNetworkingInstance requestGET:getMenberInfo parameters:@{@"id":[LBUserManage defaultManager].user_id?:@""} showHUD:YES success:^(id  _Nonnull responseObject, NSInteger code, NSString * _Nonnull message) {
        if (code == YCNetworkingStatusCodeSuccess){
            UserModel *userModel = [UserModel yy_modelWithJSON:responseObject[@"Data"]];
            [LBUserManage defaultManager].userModel = userModel;
            weakSelf.model = userModel;
        }
    }];
}

/**
 ** lineView:	   需要绘制成虚线的view
 ** lineLength:	 虚线的宽度
 ** lineSpacing:	虚线的间距
 ** lineColor:	  虚线的颜色
 **/
- (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
{
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:lineView.bounds];
    [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
    [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    //  设置虚线颜色为blackColor
    [shapeLayer setStrokeColor:lineColor.CGColor];
    //  设置虚线宽度
    [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
    [shapeLayer setLineJoin:kCALineJoinRound];
    //  设置线宽，线间距
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
    //  设置路径
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0);
    [shapeLayer setPath:path];
    CGPathRelease(path);
    //  把绘制好的虚线添加上来
    [lineView.layer addSublayer:shapeLayer];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
